package com.boshanam.view.actions.user;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.boshanam.exceptions.ApplicationException;
import com.boshanam.model.vos.domain.user.UserVOImmutable;
import com.boshanam.service.user.IUserService;

/**
 * @author Sivakumar Y, 
 * ListUsersAction.java Jan 8, 2010 3:56:08 PM
 * www.ibigbang.net
 * shiva.forums@gmail.com
 */
public class ListUsersAction extends Action {
	Log log = LogFactory.getLog(ListUsersAction.class);
	
	private IUserService userService;

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		try {
			List<UserVOImmutable> list = userService.getAllUsers();
			request.setAttribute("REG_USER_LIST", list);
		} catch (Exception e) {
			log.error("Unable to Load Users From Datastore...", e);
			throw new ApplicationException("Unable to load User list from Datastore.", e);
		}
		
		return mapping.findForward("listUsers");
	}

	/**
	 * @param userService the userService to set
	 */
	public void setUserService(IUserService IUserService) {
		this.userService = IUserService;
	}

	/**
	 * @return the userService
	 */
	public IUserService getUserService() {
		return userService;
	}
	
	

}
